<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 */
class Application_Model_Rapport extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idrapport;

    /**
     * Database var type varchar(100)
     *
     * @var string
     */
    protected $_Dategenerationrapport;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idformation;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_IdconfigStat;


    /**
     * Parent relation fk_rapport_config_stat1
     *
     * @var Application_Model_ConfigStat
     */
    protected $_ConfigStat;

    /**
     * Parent relation fk_rapport_formation1
     *
     * @var Application_Model_Formation
     */
    protected $_Formation;


    /**
     * Dependent relation fk_element_rapport_rapport1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_ElementRapport
     */
    protected $_ElementRapport;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idrapport'=>'Idrapport',
            'dategenerationrapport'=>'Dategenerationrapport',
            'idformation'=>'Idformation',
            'idconfig_stat'=>'IdconfigStat',
        ));

        $this->setParentList(array(
            'FkRapportConfigStat1'=> array(
                    'property' => 'ConfigStat',
                    'table_name' => 'ConfigStat',
                ),
            'FkRapportFormation1'=> array(
                    'property' => 'Formation',
                    'table_name' => 'Formation',
                ),
        ));

        $this->setDependentList(array(
            'FkElementRapportRapport1' => array(
                    'property' => 'ElementRapport',
                    'table_name' => 'ElementRapport',
                ),
        ));
    }

    /**
     * Sets column idrapport
     *
     * @param int $data
     * @return Application_Model_Rapport
     */
    public function setIdrapport($data)
    {
        $this->_Idrapport = $data;
        return $this;
    }

    /**
     * Gets column idrapport
     *
     * @return int
     */
    public function getIdrapport()
    {
        return $this->_Idrapport;
    }

    /**
     * Sets column dategenerationrapport
     *
     * @param string $data
     * @return Application_Model_Rapport
     */
    public function setDategenerationrapport($data)
    {
        $this->_Dategenerationrapport = $data;
        return $this;
    }

    /**
     * Gets column dategenerationrapport
     *
     * @return string
     */
    public function getDategenerationrapport()
    {
        return $this->_Dategenerationrapport;
    }

    /**
     * Sets column idformation
     *
     * @param int $data
     * @return Application_Model_Rapport
     */
    public function setIdformation($data)
    {
        $this->_Idformation = $data;
        return $this;
    }

    /**
     * Gets column idformation
     *
     * @return int
     */
    public function getIdformation()
    {
        return $this->_Idformation;
    }

    /**
     * Sets column idconfig_stat
     *
     * @param int $data
     * @return Application_Model_Rapport
     */
    public function setIdconfigStat($data)
    {
        $this->_IdconfigStat = $data;
        return $this;
    }

    /**
     * Gets column idconfig_stat
     *
     * @return int
     */
    public function getIdconfigStat()
    {
        return $this->_IdconfigStat;
    }

    /**
     * Sets parent relation IdconfigStat
     *
     * @param Application_Model_ConfigStat $data
     * @return Application_Model_Rapport
     */
    public function setConfigStat(Application_Model_ConfigStat $data)
    {
        $this->_ConfigStat = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idconfig_stat'];
        }

        $this->setIdconfigStat($primary_key);

        return $this;
    }

    /**
     * Gets parent IdconfigStat
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_ConfigStat
     */
    public function getConfigStat($load = true)
    {
        if ($this->_ConfigStat === null && $load) {
            $this->getMapper()->loadRelated('FkRapportConfigStat1', $this);
        }

        return $this->_ConfigStat;
    }

    /**
     * Sets parent relation Idformation
     *
     * @param Application_Model_Formation $data
     * @return Application_Model_Rapport
     */
    public function setFormation(Application_Model_Formation $data)
    {
        $this->_Formation = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idformation'];
        }

        $this->setIdformation($primary_key);

        return $this;
    }

    /**
     * Gets parent Idformation
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Formation
     */
    public function getFormation($load = true)
    {
        if ($this->_Formation === null && $load) {
            $this->getMapper()->loadRelated('FkRapportFormation1', $this);
        }

        return $this->_Formation;
    }

    /**
     * Sets dependent relations fk_element_rapport_rapport1
     *
     * @param array $data An array of Application_Model_ElementRapport
     * @return Application_Model_Rapport
     */
    public function setElementRapport(array $data)
    {
        $this->_ElementRapport = array();

        foreach ($data as $object) {
            $this->addElementRapport($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_element_rapport_rapport1
     *
     * @param Application_Model_ElementRapport $data
     * @return Application_Model_Rapport
     */
    public function addElementRapport(Application_Model_ElementRapport $data)
    {
        $this->_ElementRapport[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_element_rapport_rapport1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_ElementRapport
     */
    public function getElementRapport($load = true)
    {
        if ($this->_ElementRapport === null && $load) {
            $this->getMapper()->loadRelated('FkElementRapportRapport1', $this);
        }

        return $this->_ElementRapport;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Rapport
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Rapport());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Rapport::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdrapport() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idrapport = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdrapport()));
    }
}
